home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Games / Pentominoes 2.0 / Pent code / pent floating window.c < prev    next >
C/C++ Source or Header  |  1995-07-29  |  4KB  |  161 lines

  1. #include "pent floating window.h"
  2. #include "pent message.h"
  3. #include "pent meat.h"
  4. #include "pent graphics.h"
  5. #include "window layer.h"
  6. #include "program globals.h"
  7. #include <Icons.h>
  8.  
  9. #define kLeftMargin            10
  10. #define kRightMargin        10
  11. #define kTopMargin            10
  12. #define kBottomMargin        10
  13. #define kNumIcons            12
  14. #define kGapBetweenIcons    5
  15. #define kIconHeight            32
  16. #define kIconWidth            32
  17. #define kFirstIconID        1000
  18. #define kAnchoredPos        20
  19. #define kUnanchoredPos        32
  20.  
  21. static    Boolean            gSetupDone=FALSE;
  22. static    Handle            gFloatingIcon[kNumIcons];
  23.  
  24. void SetupTheFloatingWindow(WindowRef theWindow)
  25. {
  26.     short            i;
  27.     Point            thePoint;
  28.     
  29.     SetWindowHeight(theWindow, kTopMargin+kBottomMargin+kIconHeight);
  30.     SetWindowWidth(theWindow, kLeftMargin+kRightMargin+kIconWidth*kNumIcons+kGapBetweenIcons*(kNumIcons-1));
  31.     SetWindowAttributes(theWindow, kHasCloseBoxMask+kHasPaletteTitlebarMask);
  32.     SetWindowMaxDepth(theWindow, 8);
  33.     SetWindowDepth(theWindow, 8);
  34.     SetWindowIsFloat(theWindow, TRUE);
  35.     SetWindowTitle(theWindow, "\p");
  36.     SetWindowAutoCenter(theWindow, FALSE);
  37.     SetWindowIsModified(theWindow, FALSE);
  38.     thePoint.h=0;
  39.     thePoint.v=kUnanchoredPos;
  40.     SetWindowTopLeft(theWindow, thePoint);
  41.     
  42.     gShowFloat=TRUE;
  43.     
  44.     if (gSetupDone)
  45.         return;
  46.     
  47.     gSetupDone=TRUE;
  48.     for (i=0; i<kNumIcons; i++)
  49.         GetIconSuite(&gFloatingIcon[i], kFirstIconID+i, svAllLargeData);
  50. }
  51.  
  52. void OpenTheFloatingWindow(WindowRef theWindow)
  53. {
  54.     if (gAnchorFloat)
  55.         MyMoveWindow(theWindow, 0, kAnchoredPos, FALSE);
  56. }
  57.  
  58. void DisposeTheFloatingWindow(void)
  59. {
  60.     if (IndWindowExistsQQ(kMainWindow))
  61.         gShowFloat=FALSE;
  62. }
  63.  
  64. void MouseClickedInFloatingWindow(WindowRef theWindow, Point mouseLoc)
  65. {
  66.     #pragma unused(theWindow)
  67.     
  68.     short            iconIndex;
  69.     Boolean            iconIsHighlighted;
  70.     Rect            iconRect;
  71.     GameError        err;
  72.     
  73.     if (mouseLoc.v<kTopMargin) return;
  74.     if (mouseLoc.v>(GetWindowHeight(theWindow)-kBottomMargin)) return;
  75.     if (mouseLoc.h<kLeftMargin) return;
  76.     if (mouseLoc.h>(GetWindowWidth(theWindow)-kRightMargin)) return;
  77.     
  78.     mouseLoc.h-=kLeftMargin;
  79.     if (mouseLoc.h%(kIconWidth+kGapBetweenIcons)>kIconWidth) return;
  80.     
  81.     iconIndex=mouseLoc.h/(kIconWidth+kGapBetweenIcons);
  82.     if (gPieceUsed[iconIndex]) return;
  83.     
  84.     iconRect.left=kLeftMargin+iconIndex*(kIconWidth+kGapBetweenIcons);
  85.     iconRect.right=iconRect.left+kIconWidth;
  86.     iconRect.top=kTopMargin;
  87.     iconRect.bottom=kTopMargin+kIconHeight;
  88.     iconIsHighlighted=FALSE;
  89.     while (StillDown())
  90.     {
  91.         GetMouse(&mouseLoc);
  92.         if (PtInRect(mouseLoc, &iconRect))
  93.         {
  94.             if (!iconIsHighlighted)
  95.             {
  96.                 iconIsHighlighted=TRUE;
  97.                 PlotIconSuite(&iconRect, atAbsoluteCenter, ttSelected, gFloatingIcon[iconIndex]);
  98.             }
  99.         }
  100.         else
  101.         {
  102.             if (iconIsHighlighted)
  103.             {
  104.                 iconIsHighlighted=FALSE;
  105.                 PlotIconSuite(&iconRect, atAbsoluteCenter, ttNone, gFloatingIcon[iconIndex]);
  106.             }
  107.         }
  108.     }
  109.     
  110.     if (iconIsHighlighted)
  111.     {
  112.         PlotIconSuite(&iconRect, atAbsoluteCenter, ttNone, gFloatingIcon[iconIndex]);
  113.         if ((err=PlacePiece(GetIndWindowRef(kMainWindow), iconIndex, &iconIndex))!=eNoError)
  114.             DisplayMessage(err);
  115.     }
  116. }
  117.  
  118. void DrawTheFloatingWindow(WindowRef theWindow, short theDepth)
  119. {
  120.     short            i;
  121.     Rect            iconRect;
  122.     
  123.     DrawSoftWindowBorder(theWindow, theDepth, 0, FALSE);
  124.     
  125.     iconRect.left=kLeftMargin;
  126.     iconRect.right=kLeftMargin+kIconWidth;
  127.     iconRect.top=kTopMargin;
  128.     iconRect.bottom=kTopMargin+kIconHeight;
  129.     for (i=0; i<kNumIcons; i++)
  130.     {
  131.         PlotIconSuite(&iconRect, atAbsoluteCenter, gPieceUsed[i] ? ttDisabled : ttNone, gFloatingIcon[i]);
  132.         iconRect.left+=kIconWidth+kGapBetweenIcons;
  133.         iconRect.right+=kIconWidth+kGapBetweenIcons;
  134.     }
  135. }
  136.  
  137. void ToggleShowFloatingWindow(void)
  138. {
  139.     Boolean            nowShowing;
  140.     
  141.     nowShowing=gShowFloat;
  142.     if (IndWindowExistsQQ(kMainWindow))
  143.     {
  144.         if (nowShowing)
  145.             CloseTheWindow(GetIndWindowRef(kFloatingWindow));
  146.         else
  147.             OpenTheIndWindow(kFloatingWindow, kOpenOldIfPossible);
  148.     }
  149.     gShowFloat=!nowShowing;
  150. }
  151.  
  152. void ToggleAnchorFloatingWindow(void)
  153. {
  154.     WindowRef        theWindow;
  155.     
  156.     theWindow=GetIndWindowRef(kFloatingWindow);
  157.     gAnchorFloat=!gAnchorFloat;
  158.     if (theWindow!=0L)
  159.         MyMoveWindow(theWindow, 0, gAnchorFloat ? kAnchoredPos : kUnanchoredPos, FALSE);
  160. }
  161.